#include<bits/stdc++.h>
using namespace std;
#define mid (l+r)/2
const int N=1e5;
int T,n,m,l,V,ans,lt,rt;
bool h[3];
int d[N+1],v[N+1],a[N+1],p[N+1],L[N+1],R[N+1];
vector<int>vv[3001],uu[3001];
int du[3001];
bool check()
{
    for(int i=1;i<=m;i++) if(du[i]!=0) return 0;
    return 1;
}
int getnum()
{
    int nu=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(L[j]<=i&&R[j]>=i)
            {
                vv[i].push_back(j);
                uu[j].push_back(i);
                du[i]++;
            }
        }
    }
    while(1)
    {
        if(check()) break;
        nu++;
        int maxn=0,rr=-1;
        for(int i=1;i<=m;i++)
        {
            if(du[i]>maxn)
            {
                maxn=du[i];
                rr=i;
            }
        }
        for(int i=0;i<vv[rr].size();i++)
        {
            for(int j=0;j<uu[vv[rr][i]].size();j++) du[uu[vv[rr][i]][j]]--;
            uu[vv[rr][i]].clear();
        }
    }
    return m-nu;
}
int rnearest(int k)
{
    int l=1,r=m,ans=0;
    while(l<=r)
    {
        if(p[mid]<=k)
        {
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return ans;
}
int lnearest(int k)
{
    int l=1,r=m,ans=0;
    while(l<=r)
    {
        if(p[mid]>=k)
        {
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    return ans;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--)
    {
        memset(L,0,sizeof(L));
        memset(R,0,sizeof(R));
        h[0]=h[1]=h[2]=1;
        ans=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]>0) h[0]=h[2]=0;
            else if(a[i]==0) h[1]=h[2]=0;
            else h[0]=h[1]=0;
        }
        for(int i=1;i<=m;i++) cin>>p[i];
        sort(p+1,p+m+1);
        if(h[0])
        {
            for(int i=1;i<=n;i++) if(d[i]<=p[m]&&v[i]>V) ans++;
            cout<<ans<<" ";
            if(ans==0) cout<<m<<"\n";
            else cout<<m-1<<"\n";
        }
        if(h[1])
        {
            int s;
            for(int i=1;i<=n;i++)
            {
                s=(V-v[i])*(V+v[i])/(2*a[i]);
                if(v[i]>V)
                {
                    if(p[m]>=d[i]) ans++;
                }
                else if(p[m]>d[i]+s) ans++;
            }
            cout<<ans<<" ";
            if(ans==0) cout<<m<<"\n";
            else cout<<m-1<<"\n";
        }
        if(h[2])
        {
            for(int i=0;i<=3001;i++)
            {
                vv[i].clear();
                uu[i].clear();
                du[i]=0;
            }
            int s;
            for(int i=1;i<=n;i++)
            {
                s=(V-v[i])*(V+v[i])/(2*a[i]);
                if(v[i]<V) continue;
                else
                {
                    rt=rnearest(s+d[i]);
                    if(d[i]<=p[rt])
                    {
                        L[i]=lnearest(d[i]);
                        R[i]=rt;
                        ans++;
                    }
                }
            }
            cout<<ans<<" ";
            if(ans==0) cout<<m<<"\n";
            else cout<<getnum()+2<<"\n";
        }
    }
    return 0;
}
